﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OrderControl
{
    class Order
    {
        //订单编号 订单日期 订单客户 订单明细
        public int OrderNumber { get; set; }
        public DateTime OrderDate { get; set; }
        public string OrderUser { get; set; }
        public OrderItem orderItem { get; set; }
        public double amount { get; set; }
        public Order()
        {

        }
        public Order(OrderItem orderItem, string User)
        {
            this.OrderNumber = OrderService.OrderNumber;
            this.OrderDate = DateTime.Now;
            this.OrderUser = User;
            this.orderItem = orderItem;
            this.AddUp(orderItem);
        }
        public void AddUp(OrderItem orderItem)
        {
            foreach(Item t in orderItem.orderItemList.Keys)
            {
                amount += t.Price * orderItem.orderItemList[t];
            }
        }
        public override bool Equals(object obj)
        {
            Order order = obj as Order;
            return order != null&& order.OrderNumber == OrderNumber;
        }
        public override int GetHashCode()
        {
            return base.GetHashCode();
        }
        public override string ToString()
        {
            return this.OrderNumber+"\t"+this.OrderDate+"\t"+this.OrderUser;
        }
    }
}
